package top.kuxiao.crmserver.intercepor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
import top.kuxiao.crmserver.intercepor.LoginInterceptor;

/**
 * <p>
 * 拦截器的配置
 * </p>
 *
 * @author xiaozhang
 * @since 2022-01-13
 */
@Configuration
public class WebMVCConfigAddInterceptor extends WebMvcConfigurationSupport {

    @Autowired
    LoginInterceptor loginInterceptor;

    @Override //重写添加拦截器的方法
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor).
                //拦截谁
                        addPathPatterns("/**")
                //不拦截谁
                        .excludePathPatterns("/login/**")
                //swagger
                        .excludePathPatterns("/swagger**/**")
                        .excludePathPatterns("/webjars/**")
                        .excludePathPatterns("/v3/**")
                        .excludePathPatterns("/doc.html");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/swagger-ui/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/");
        super.addResourceHandlers(registry);
    }

}
